/**
 * 数据显示表格
 */
import React, { Component } from 'react';
import { Modal, Table } from 'antd';

class ValidatorTable extends Component{
    constructor(props) {
        super(props);
    }

    render(){
        const { data, showTable, type, text } = this.props;
        let tableData = [];
        let errorState = text=='失败';
        const total = [
            {
                title: '设置信息',
                value: 'settingComm',
                columns: [
                    {
                        title: "主键",
                        dataIndex: "id",
                        align: 'center',
                        width: '20%'
                    }, {
                        title: "设置ID",
                        dataIndex: "idMain",
                        align: 'center',
                        width: '20%',
                    }, {
                        title: "函数",
                        dataIndex: "fun",
                        align: 'center',
                        width: '20%',
                    }, {
                        title: "参数",
                        dataIndex: "param",
                        align: 'center',
                        width: '20%',
                    }, {
                        title: "信息",
                        dataIndex: "msg",
                        align: 'center',
                        width: '20%',
                        render:(text, record)=>{
                            if(errorState){
                                return <label style={{ color: 'red' }}>{text}</label>
                            }else{
                                return <label>{text}</label>
                            }
                        }
                    }
                ]
            }, {
                title: '允许IP',
                value: 'allowIps',
                columns: [
                    {
                        title: "主键",
                        dataIndex: "id",
                        align: 'center',
                        width: '20%'
                    }, {
                        title: "开始IP",
                        dataIndex: "startIp",
                        align: 'center',
                        width: '25%',
                    }, {
                        title: "结束IP",
                        dataIndex: "endIp",
                        align: 'center',
                        width: '25%',
                    }, {
                        title: "信息",
                        dataIndex: "msg",
                        align: 'center',
                        width: '30%',
                        render:(text, record)=>{
                            if(errorState){
                                return <label style={{ color: 'red' }}>{text}</label>
                            }else{
                                return <label>{text}</label>
                            }
                        }
                    }
                ]
            }, {
                title: '拒绝IP',
                value: 'denyIps',
                columns: [
                    {
                        title: "主键",
                        dataIndex: "id",
                        align: 'center',
                        width: '20%'
                    }, {
                        title: "开始IP",
                        dataIndex: "startIp",
                        align: 'center',
                        width: '25%',
                    }, {
                        title: "结束IP",
                        dataIndex: "endIp",
                        align: 'center',
                        width: '25%',
                    }, {
                        title: "信息",
                        dataIndex: "msg",
                        align: 'center',
                        width: '30%',
                        render:(text, record)=>{
                            if(errorState){
                                return <label style={{ color: 'red' }}>{text}</label>
                            }else{
                                return <label>{text}</label>
                            }
                        }
                    }
                ]
            }, {
                title: '允许版本',
                value: 'allowVersions',
                columns: [
                    {
                        title: "主键",
                        dataIndex: "id",
                        align: 'center',
                        width: '20%'
                    }, {
                        title: "版本",
                        dataIndex: "version",
                        align: 'center',
                        width: '50%',
                    }, {
                        title: "信息",
                        dataIndex: "msg",
                        align: 'center',
                        width: '30%',
                        render:(text, record)=>{
                            if(errorState){
                                return <label style={{ color: 'red' }}>{text}</label>
                            }else{
                                return <label>{text}</label>
                            }
                        }
                    }
                ]
            }, {
                title: '拒绝版本',
                value: 'denyVersions',
                columns: [
                    {
                        title: "主键",
                        dataIndex: "id",
                        align: 'center',
                        width: '20%'
                    }, {
                        title: "版本",
                        dataIndex: "version",
                        align: 'center',
                        width: '50%',
                    }, {
                        title: "信息",
                        dataIndex: "msg",
                        align: 'center',
                        width: '30%',
                        render:(text, record)=>{
                            if(errorState){
                                return <label style={{ color: 'red' }}>{text}</label>
                            }else{
                                return <label>{text}</label>
                            }
                        }
                    }
                ]
            }, {
                title: '允许mac',
                value: 'allowMacs',
                columns: [
                    {
                        title: "主键",
                        dataIndex: "id",
                        align: 'center',
                        width: '20%'
                    }, {
                        title: "MAC地址",
                        dataIndex: "mac",
                        align: 'center',
                        width: '50%',
                    }, {
                        title: "信息",
                        dataIndex: "msg",
                        align: 'center',
                        width: '30%',
                        render:(text, record)=>{
                            if(errorState){
                                return <label style={{ color: 'red' }}>{text}</label>
                            }else{
                                return <label>{text}</label>
                            }
                        }
                    }
                ]
            }, {
                title: '拒绝mac',
                value: 'denyMacs',
                columns: [
                    {
                        title: "主键",
                        dataIndex: "id",
                        align: 'center',
                        width: '20%'
                    }, {
                        title: "MAC地址",
                        dataIndex: "mac",
                        align: 'center',
                        width: '50%',
                    }, {
                        title: "信息",
                        dataIndex: "msg",
                        align: 'center',
                        width: '30%',
                        render:(text, record)=>{
                            if(errorState){
                                return <label style={{ color: 'red' }}>{text}</label>
                            }else{
                                return <label>{text}</label>
                            }
                        }
                    }
                ]
            }, {
                title: '收集信息',
                value: 'collectInfos',
                columns: [
                    {
                        title: "主键",
                        dataIndex: "id",
                        align: 'center',
                        width: '15%'
                    }, {
                        title: "客户端类别",
                        dataIndex: "idMain",
                        align: 'center',
                        width: '17%',
                    }, {
                        title: "函数",
                        dataIndex: "fun",
                        align: 'center',
                        width: '17%',
                    }, {
                        title: "参数",
                        dataIndex: "param",
                        align: 'center',
                        width: '17%',
                    }, {
                        title: "版本信息ID",
                        dataIndex: "versionId",
                        align: 'center',
                        width: '17%',
                    }, {
                        title: "信息",
                        dataIndex: "msg",
                        align: 'center',
                        width: '17%',
                        render:(text, record)=>{
                            if(errorState){
                                return <label style={{ color: 'red' }}>{text}</label>
                            }else{
                                return <label>{text}</label>
                            }
                        }
                    }
                ]
            }, {
                title: '版本设置',
                value: 'settingItem',
                columns: [
                    {
                        title: "主键",
                        dataIndex: "id",
                        align: 'center',
                        width: '10%'
                    }, {
                        title: "类别",
                        dataIndex: "idMain",
                        align: 'center',
                        width: '15%',
                    }, {
                        title: "函数",
                        dataIndex: "fun",
                        align: 'center',
                        width: '15%',
                    }, {
                        title: "参数",
                        dataIndex: "param",
                        align: 'center',
                        width: '15%',
                    }, {
                        title: "是否推送",
                        dataIndex: "calcetag",
                        align: 'center',
                        width: '15%',
                        render: (text, record)=>{
                            if(text){
                                return '是'
                            }else{
                                return '否'
                            }
                        }
                    }, {
                        title: "版本信息ID",
                        dataIndex: "versionId",
                        align: 'center',
                        width: '15%',
                    }, {
                        title: "信息",
                        dataIndex: "msg",
                        align: 'center',
                        width: '15%',
                        render:(text, record)=>{
                            if(errorState){
                                return <label style={{ color: 'red' }}>{text}</label>
                            }else{
                                return <label>{text}</label>
                            }
                        }
                    }
                ]
            }, {
                title: '客户端信息',
                value: 'clientInfo',
                columns: [
                    {
                        title: "主键",
                        dataIndex: "id",
                        align: 'center',
                        width: '10%'
                    }, {
                        title: "客户端类别",
                        dataIndex: "idMain",
                        align: 'center',
                        width: '16%',
                    }, {
                        title: "函数",
                        dataIndex: "fun",
                        align: 'center',
                        width: '16%',
                    }, {
                        title: "参数",
                        dataIndex: "param",
                        align: 'center',
                        width: '16%',
                    }, {
                        title: "版本信息ID",
                        dataIndex: "versionId",
                        align: 'center',
                        width: '16%',
                    }, {
                        title: "信息",
                        dataIndex: "msg",
                        align: 'center',
                        width: '26%',
                        render:(text, record)=>{
                            if(errorState){
                                return <label style={{ color: 'red' }}>{text}</label>
                            }else{
                                return <label>{text}</label>
                            }
                        }
                    }
                ]
            }, {
                title: '动作信息',
                value: 'actions',
                columns: [
                    {
                        title: "主键",
                        dataIndex: "id",
                        align: 'center',
                        width: '8%'
                    }, {
                        title: "动作名称",
                        dataIndex: "idMain",
                        align: 'center',
                        width: '10%',
                    }, {
                        title: "索引",
                        dataIndex: "index",
                        align: 'center',
                        width: '10%',
                    }, {
                        title: "状态判断",
                        dataIndex: "ifstatus",
                        align: 'center',
                        width: '11%',
                    }, {
                        title: "动作判断",
                        dataIndex: "ifactions",
                        align: 'center',
                        width: '11%',
                    }, {
                        title: "执行判断",
                        dataIndex: "executeif",
                        align: 'center',
                        width: '10%',
                    }, {
                        title: "合并到动作",
                        dataIndex: "mergetoaction",
                        align: 'center',
                        width: '10%',
                    }, {
                        title: "参数",
                        dataIndex: "params",
                        align: 'center',
                        width: '10%',
                    }, {
                        title: "版本信息ID",
                        dataIndex: "versionId",
                        align: 'center',
                        width: '10%',
                    }, {
                        title: "信息",
                        dataIndex: "msg",
                        align: 'center',
                        width: '10%',
                        render:(text, record)=>{
                            if(errorState){
                                return <label style={{ color: 'red' }}>{text}</label>
                            }else{
                                return <label>{text}</label>
                            }
                        }
                    }
                ]
            }, {
                title: '区分语言配置',
                value: 'validateLangVo',
                columns: [
                    {
                        title: "主键",
                        dataIndex: "id",
                        align: 'center',
                        width: '15%'
                    }, {
                        title: "语言",
                        dataIndex: "languageNo",
                        align: 'center',
                        width: '25%',
                    }, {
                        title: "描述",
                        dataIndex: "description",
                        align: 'center',
                        width: '30%',
                    }, {
                        title: "信息",
                        dataIndex: "msg",
                        align: 'center',
                        width: '30%',
                        render:(text, record)=>{
                            if(errorState){
                                return <label style={{ color: 'red' }}>{text}</label>
                            }else{
                                return <label>{text}</label>
                            }
                        }
                    }
                ]
            }, {
                title: '升级包',
                value: 'patchInfo',
                columns: [
                    {
                        title: "主键",
                        dataIndex: "id",
                        align: 'center',
                        width: '4%'
                    }, {
                        title: "升级包类型",
                        dataIndex: "type",
                        align: 'center',
                        width: '8%',
                    }, {
                        title: "索引",
                        dataIndex: "index",
                        align: 'center',
                        width: '8%',
                    }, {
                        title: "包的位置",
                        dataIndex: "path",
                        align: 'center',
                        width: '8%',
                    }, {
                        title: "md5",
                        dataIndex: "md5",
                        align: 'center',
                        width: '8%',
                    }, {
                        title: "大小",
                        dataIndex: "size",
                        align: 'center',
                        width: '8%'
                    }, {
                        title: "本地目录",
                        dataIndex: "localdir",
                        align: 'center',
                        width: '8%',
                    }, {
                        title: "参数",
                        dataIndex: "args",
                        align: 'center',
                        width: '8%',
                    }, {
                        title: "基础版本",
                        dataIndex: "baseversion",
                        align: 'center',
                        width: '8%',
                    }, {
                        title: "版本信息ID",
                        dataIndex: "versionId",
                        align: 'center',
                        width: '8%',
                    }, {
                        title: "语言编号",
                        dataIndex: "langId",
                        align: 'center',
                        width: '8%',
                    }, {
                        title: "信息",
                        dataIndex: "msg",
                        align: 'center',
                        width: '8%',
                        render:(text, record)=>{
                            if(errorState){
                                return <label style={{ color: 'red' }}>{text}</label>
                            }else{
                                return <label>{text}</label>
                            }
                        }
                    }
                ]
            }, {
                title: '升级条件',
                value: 'patchCondition',
                columns: [
                    {
                        title: "主键",
                        dataIndex: "id",
                        align: 'center',
                        width: '15%'
                    }, {
                        title: "函数",
                        dataIndex: "fun",
                        align: 'center',
                        width: '17%',
                    }, {
                        title: "检查路径",
                        dataIndex: "checkpath",
                        align: 'center',
                        width: '17%',
                    }, {
                        title: "参数",
                        dataIndex: "param",
                        align: 'center',
                        width: '17%',
                    }, {
                        title: "升级包信息ID",
                        dataIndex: "patchId",
                        align: 'center',
                        width: '17%',
                    }, {
                        title: "信息",
                        dataIndex: "msg",
                        align: 'center',
                        width: '17%',
                        render:(text, record)=>{
                            if(errorState){
                                return <label style={{ color: 'red' }}>{text}</label>
                            }else{
                                return <label>{text}</label>
                            }
                        }
                    }
                ]
            }, {
                title: '泡泡',
                value: 'popupInfo',
                columns: [
                    {
                        title: "主键",
                        dataIndex: "id",
                        align: 'center',
                        width: '8%'
                    }, {
                        title: "泡泡类别",
                        dataIndex: "type",
                        align: 'center',
                        width: '8%',
                    }, {
                        title: "泡泡链接",
                        dataIndex: "link",
                        align: 'center',
                        width: '8%',
                    }, {
                        title: "泡泡文字",
                        dataIndex: "text",
                        align: 'center',
                        width: '8%',
                    }, {
                        title: "参数",
                        dataIndex: "param",
                        align: 'center',
                        width: '8%',
                    }, {
                        title: "自动关闭时间",
                        dataIndex: "delay",
                        align: 'center',
                        width: '8%'
                    }, {
                        title: "是否等待",
                        dataIndex: "wait",
                        align: 'center',
                        width: '8%',
                    }, {
                        title: "版本信息ID",
                        dataIndex: "versionId",
                        align: 'center',
                        width: '8%',
                    }, {
                        title: "语言编号",
                        dataIndex: "langId",
                        align: 'center',
                        width: '8%',
                    }, {
                        title: "类型",
                        dataIndex: "uimode",
                        align: 'center',
                        width: '8%',
                    }, {
                        title: "信息",
                        dataIndex: "msg",
                        align: 'center',
                        width: '8%',
                        render:(text, record)=>{
                            if(errorState){
                                return <label style={{ color: 'red' }}>{text}</label>
                            }else{
                                return <label>{text}</label>
                            }
                        }
                    }
                ]
            }, {
                title: '泡泡条件',
                value: 'popupCondition',
                columns: [
                    {
                        title: "主键",
                        dataIndex: "id",
                        align: 'center',
                        width: '15%'
                    }, {
                        title: "函数",
                        dataIndex: "fun",
                        align: 'center',
                        width: '17%',
                    }, {
                        title: "检查路径",
                        dataIndex: "checkpath",
                        align: 'center',
                        width: '17%',
                    }, {
                        title: "参数",
                        dataIndex: "param",
                        align: 'center',
                        width: '17%',
                    }, {
                        title: "泡泡信息ID",
                        dataIndex: "popupId",
                        align: 'center',
                        width: '17%',
                    }, {
                        title: "信息",
                        dataIndex: "msg",
                        align: 'center',
                        width: '17%',
                        render:(text, record)=>{
                            if(errorState){
                                return <label style={{ color: 'red' }}>{text}</label>
                            }else{
                                return <label>{text}</label>
                            }
                        }
                    }
                ]
            }
        ];
        
        for(let i=0; i<data.length; i++){
            let obj = data[i].data;
            if(text!=='成功'){
                obj.msg = data[i].msg;
            }
            tableData.push(obj);
        }

        const columns = total.filter(v=>v.value==type.value)[0].columns

        return(
            <Modal 
                visible={true}
                width="80%"
                title={type.title+text}
                footer={null}
                maskClosable={false}
                onCancel={()=>showTable([] , false, '')}
            >
                <Table
                    dataSource={tableData}
                    columns={columns}
                    pagination={false}
                    scroll={{y: 500}}
                />
            </Modal>
        )
    }
}

export default ValidatorTable